function [L_H ]=construct_Hypergraphs_knn_pathway_weight(W ,k_nn ,z)
% load('demo.mat');
% W=K_COM2;
% k_nn=50;
% z=proteinGeneMatrixNow;

L_H =[]; 
n_size =size (W ,1 ); 
n_vertex =n_size ; 
n_edge =n_size ; 


H =zeros (n_vertex ,n_edge ); 
W_ee =zeros (n_vertex ,n_edge ); 

for i =1 :n_vertex 
ll =W (i ,:); 
ll (i )=[];     %ll是第i个疾病与其他所有疾病的相关性
[B ,index_i ]=sort (ll ,'descend' ); %index_i是降序后疾病的原本序号
k_ii =index_i (1 :k_nn ); %取前k个关联最高的疾病/基因

% 找出当前列为1的行索引
proteinIndices = find(z(:, i) == 1);

if ~isempty(proteinIndices)
    proteinRowsWithGene = z(proteinIndices, :);
    finalRowVector = any(proteinRowsWithGene); 
    finalColumnIndices = find(finalRowVector);
    if  size(finalColumnIndices,2)<12
        H(i,finalColumnIndices)=1;
        W_ee (i ,finalColumnIndices )=ll (finalColumnIndices ); 
       
    else
         H (i ,k_ii )=1 ;        %将前k个关联最高的疾病的超图邻接矩阵置1，代表这一疾病属于的超边
         W_ee (i ,k_ii )=ll (k_ii );  %每个超边的权重
    end 
else 
    H (i ,k_ii )=1 ;        %将前k个关联最高的疾病的超图邻接矩阵置1，代表这一疾病属于的超边
    W_ee (i ,k_ii )=ll (k_ii );  %每个超边的权重
end

end

d_v =sum (H'); %该疾病在多少个超边中
d_e =sum (H ); %该超边包含多少个疾病

D_v =diag (d_v ); 
D_e_I =diag (d_e.^(-1 )); 
D_e_I (D_e_I ==inf )=0 ; 

W_e =sum (W_ee' ); %对每个疾病的超边权重求和 
a =W_e ; 
a =(a -min (a ))/(max (a )-min (a )); 
A =diag (a ); 


I =eye (n_size ); 


Thta =A *D_e_I ; 
Thta =H *Thta *H' ; 
Thta =(D_v ^(-0.5 ))*Thta *(D_v ^(-0.5 )); 

L_H =I -Thta ; 
end